package com.zby.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zby.admin.pojo.Brand;
import com.zby.admin.pojo.dto.BrandDto;
import com.zby.admin.pojo.vo.BrandVo;
import com.zby.admin.service.BrandService;
import com.zby.utils.Result;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

/**
 * @author wuyanzhu
 */
@RestController
@RequestMapping("/brand")
public class BrandController {
    @Resource
    private BrandService brandService;
    /**
     * 获取品牌列表
     *
     */
    @GetMapping("/getBrandList")
    public Result<IPage<BrandVo>>getBrandList(@RequestParam(defaultValue ="1") Integer page,@RequestParam(defaultValue = "10") Integer pageSize) {
       IPage<BrandVo> response = brandService.getBrandList(page, pageSize);
        return Result.success(response);
    }
    /**
     * 添加品牌
     *
     */
    @PostMapping("/insert")
    public Result<BrandVo> insert(@RequestBody BrandDto brandDto, HttpServletRequest request) {
        boolean insert = brandService.insertBrand(brandDto, request);
        if (insert){
            return Result.success();
        }
        return Result.error(500,"添加失败");
    }
    /**
     * 修改品牌
     *
     */
    @PutMapping("/update")
    public Result<BrandVo> update(@RequestBody BrandDto brandDto, HttpServletRequest request) {
        boolean update = brandService.updateData(brandDto, request);
        if (update){
            return Result.success();
        }
        return Result.error(500,"修改失败");
    }
    /**
     * 删除品牌
     *
     */
    @DeleteMapping("/delete")
    public Result<Integer> delete(@RequestParam Integer id) {
        boolean removedById = brandService.removeById(id);
        if (removedById){
            return Result.success();
        }
        return Result.error(500,"删除失败");
    }

}
